//
//  DetailSheQuViewCell.m
//  TravelYo
//
//  Created by lanou3g on 15/10/29.
//  Copyright © 2015年 TravelYo. All rights reserved.
//

#import "DetailSheQuViewCell.h"

@implementation DetailSheQuViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        [self addSubCellViews];
    }
    return self;
}



// 添加cell子视图
- (void)addSubCellViews
{
    UIView *backGroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, kScreenWidth - 20, 170)];
    backGroundView.backgroundColor = [UIColor blueColor];
    backGroundView.alpha = 0.05;
    backGroundView.layer.cornerRadius = 10;
    backGroundView.layer.masksToBounds = YES;
    [self.contentView addSubview:backGroundView];
    
    
    
    
    // 头像
    self.avatarImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 60, 60)];
    self.avatarImage.backgroundColor = [UIColor brownColor];
    self.avatarImage.layer.cornerRadius = self.avatarImage.frame.size.width / 2;
    self.avatarImage.layer.masksToBounds = YES;
    [self.contentView addSubview:self.avatarImage];

    // 用户名
    self.userNameLable = [[UILabel alloc] initWithFrame:CGRectMake(self.avatarImage.right + 10, self.avatarImage.top + 5, kScreenWidth / 2, 35)];
    //self.userNameLable.backgroundColor = [UIColor brownColor];
    [self.contentView addSubview:self.userNameLable];
    
    
    UILabel *toplLable = [[UILabel alloc] initWithFrame:CGRectMake(self.userNameLable.right + 10, self.userNameLable.top, 40, 35)];
   // toplLable.backgroundColor = [UIColor brownColor];
    toplLable.text = @"置顶";
    toplLable.textColor = [UIColor blueColor];
    toplLable.alpha = 0.5;
    [self.contentView addSubview:toplLable];

    
    // 标题
    self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(self.userNameLable.left, self.userNameLable.bottom + 5, kScreenWidth - 30 - self.avatarImage.frame.size.width, 60)];
    //self.titleLable.backgroundColor = [UIColor brownColor];
    self.titleLable.numberOfLines = 0;
    [self.contentView addSubview:self.titleLable];
    
    // 时间
    self.timeLable = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLable.left, self.titleLable.bottom + 10, kScreenWidth / 2 , 30)];
    //self.timeLable.backgroundColor = [UIColor brownColor];
    [self.contentView addSubview:self.timeLable];
    
    // 评论
    self.replysLable = [[UILabel alloc] initWithFrame:CGRectMake(self.timeLable.right + 10, self.timeLable.top, kScreenWidth / 4, 30)];
    //self.replysLable.backgroundColor = [UIColor brownColor];
    [self.contentView addSubview:self.replysLable];
    
    
}


// 重写set方法
- (void)setModel:(SheQuDetailModel *)model
{
    
    // 对model赋值
    // 图片
    [self.avatarImage sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:nil];
    // 用户名
    self.userNameLable.text = model.username;
    self.userNameLable.alpha = 0.8;
    // 标题
    self.titleLable.text = model.title;
    self.titleLable.alpha = 0.8;
    // 时间
    NSDate *data = [NSDate dateWithTimeIntervalSince1970:[model.lastpost intValue]];
    NSDateFormatter *fomatter = [[NSDateFormatter alloc] init];
    [fomatter setDateFormat:@"YY-MM-dd"];
    NSString *showtimeNew = [fomatter stringFromDate:data];
    self.timeLable.text = showtimeNew;
    self.timeLable.alpha = 0.8;
    // 评论
    self.replysLable.text = [NSString stringWithFormat:@"评论:%@",model.replys];
    self.replysLable.tintColor = [UIColor orangeColor];
    self.replysLable.alpha = 0.8;

    
}










- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
